package com.omn.listazakupow.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;

import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.theme.ThemeDisplay;
import com.omn.listazakupow.db.model.GrupyTowarow;
import com.omn.listazakupow.db.model.ListaZakupow;
import com.omn.listazakupow.db.model.PozycjeListyZakupow;
import com.omn.listazakupow.db.service.GrupyTowarowLocalServiceUtil;
import com.omn.listazakupow.db.service.ListaZakupowLocalServiceUtil;
import com.omn.listazakupow.db.service.PozycjeListyZakupowLocalServiceUtil;

@Controller
@RequestMapping("VIEW")
public class ViewGrupyTowarowController {

	@RequestMapping("view")
	public void handleActionRequest(ActionRequest request,
			ActionResponse response) throws Exception {
	}

	@RequestMapping("view")
	public ModelAndView handleRenderRequest(RenderRequest request,
			RenderResponse response) throws Exception {
		Map<String, Object> model = new HashMap<String, Object>();

		/* Read params */
		ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
		User user = themeDisplay.getUser();

		/* Load List */
		DynamicQuery dq = DynamicQueryFactoryUtil.forClass(GrupyTowarow.class);
		dq.addOrder( PropertyFactoryUtil.forName( "id" ).desc() );

		List<GrupyTowarow> lgt = GrupyTowarowLocalServiceUtil.dynamicQuery(dq);
		model.put("lgt", lgt);
		
		return new ModelAndView("viewGrupyTowarow", model);
	}

	@RequestMapping
	protected String defaultView() {
		return "view";
	}

}
